home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MCASM.RAR / MC_ASM.EXE / WROX_ASM / CH12 / COMMON / MANAGER.H < prev    next >
C/C++ Source or Header  |  1994-08-24  |  4KB  |  106 lines

  1. /*
  2. * This program is a simple expanded/extanded memory manger
  3. * It lets you to allocate and use memory blocks of any size
  4. * (but normally they should be at least 200 byte per block)
  5. * Each block takes about 16 bytes of conventional memory
  6. *  and manager takes 64K expanded/extanded memory for its
  7. *  internal needs
  8. * Written by Podvoysky E. & Kiselev J. CZ 1994.
  9. */
  10.  
  11. // !!!!!!!!! Attention !!!!!!!!!!!!
  12.  
  13. #define EMM
  14. /*
  15. * if you want to use this program with EMM386.SYS driver
  16. * please, uncomment  line " #define EMM "
  17. * I don't know why, but normal version of
  18. * our program  doesn't work with this particular driver
  19. */
  20.  
  21. /* Low-level routines support both XMS and EMS protocols, so
  22. *  you need not to trouble about it.
  23. *  Ask XMS/EMS drivers to make as more handles as possible
  24. *  you may take only (64*numhandles) kilobytes of memory
  25. *  You MUST call manager_initialize() before using memory,
  26. *  and (it's important!!!!) manager_finish(TRUE) at the end
  27. *  of your program ( to return taken extended memory to system)
  28. */
  29.  
  30.  
  31. #ifndef MANAGER_H
  32. #define MANAGER_H
  33.  
  34. #include "common.h"
  35.  
  36. #define NEAR far
  37. #define FAR huge
  38. #define SIZE_TYPE long
  39.  
  40. #define USER_HANDLE WORD
  41. #define NULL_HANDLE 0xFFFFU
  42.  
  43. //------------- high - level routines
  44. int manager_initialize(); // don't forget to call it!
  45.     // returns -1 if error occured
  46.  
  47. void manager_finish(BOOL dispose_conv);
  48.  
  49. // allocate memory block
  50. // returns USER_HANDLE you will use as identifier of the block
  51. // returns NULL_HANDLE if error occured
  52. USER_HANDLE  EXM_alloc(SIZE_TYPE size);
  53. // Remember! Each block eates about 16 bytes of conventional memory
  54.  
  55. // free memory block
  56. int EXM_free(USER_HANDLE handle);  // returns -1 if error occured
  57.  
  58. // move from  ex... (extra!) memory to conventional
  59. int EXM_move_to_conv(void FAR *dest, USER_HANDLE source_handle,
  60.             SIZE_TYPE offset, SIZE_TYPE size);
  61.     // returns -1 if error occured
  62.  
  63. // move from conventional memory to  extra
  64. int EXM_move_to_ext(USER_HANDLE dest_handle, void FAR *source,
  65.             SIZE_TYPE offset, SIZE_TYPE size);
  66.     // returns -1 if error occured
  67. int EXM_to_EXM(USER_HANDLE dest_handle, SIZE_TYPE dest_offset,
  68.            USER_HANDLE source_handle, SIZE_TYPE source_offset,
  69.            SIZE_TYPE size);
  70.     // returns -1 if error occured
  71. long EXM_coreleft();  //available extended memory in bytes
  72.     // may report more, than ypu really may get
  73.     // if XMS/EMM driver doesn't provides enough handles
  74.     // manager use handles of 64K  size
  75.  
  76. extern BOOL EXM_initialized;
  77.  
  78. extern int EXM_error;
  79. /* 0   - Ok
  80. *  < 0 - returned system errors
  81. *  1   - not enough conventional memory
  82. *  2   - not enough extra memory
  83. *  3   - invalide user handle
  84. *  4   - attempt to read/write beyond end of allocated block
  85. *  5   - invalid parameter in routine call (e.g.: allocate -1000 bytes )
  86. * 10   - manager was not initialized
  87. *  100 -   some error reported by low-level system
  88. *  101 -   internal structure error (invalid handle)
  89. *  102 -   internal structure error (free marking)
  90. *  103 -   internal structure error (size of block and offset in handle)
  91. */
  92.  
  93. /* low - level procedures */
  94. extern "C" int init_ext_mem();
  95. extern "C" int get_free_ext_mem(void);
  96. extern "C" int alloc_ext_mem(int);
  97. extern "C" int free_ext_mem(int);
  98. extern "C" int move_ext_mem(int handle,WORD offset,WORD size,
  99.             void* real_address,BYTE direction_flag);
  100. // direction_flag 0 - from conventional to extra
  101. //                1 - from extra to conventional
  102.  
  103. extern "C" int  move_ext2ext(int dest_handle,int dest_offset,
  104.             int source_handle,int source_offset,int size);
  105.  
  106. #endif